package com.hfi.restful.security;

import com.hfi.security.core.authentication.authorize.AuthorizeConfigProvider;
import org.springframework.http.HttpMethod;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configurers.ExpressionUrlAuthorizationConfigurer;
import org.springframework.stereotype.Component;

/**
 * @author ChangLiang
 * @date 2019/9/9
 */
@Component
public class DemoAuthorizeConfigProvider implements AuthorizeConfigProvider {

    @Override
    public boolean config(ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry config) {
        config
                // 要写到*的前面 这样会位于链表的前面
                .antMatchers(HttpMethod.GET,"/user/me").hasRole("REAL_NAME")
                .antMatchers(HttpMethod.GET,"/user/*").hasRole("REGISTER")
                .antMatchers(HttpMethod.DELETE,"/user/*").hasRole("REAL_NAME")
                .antMatchers(HttpMethod.POST,"/user").hasRole("REAL_NAME_FACE")
                // 测试/api/person 加入/api/*
                .antMatchers("/user/register","/api/*").permitAll();
        return false;
    }
}
